package com.yipao.wx.web.dev;

import com.yipao.core.util.ResponseUtil;
import com.yipao.core.validator.Order;
import com.yipao.core.validator.Sort;
import com.yipao.db.service.devinfo.DevInfoService;
import com.yipao.wx.service.LbsTableService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 设备
 *
 * @author voyboy
 */
@RestController
@RequestMapping("/wx")
@Validated
public class WxDevController {
    @Resource
    private LbsTableService lbsTableService;
    @Resource
    private DevInfoService devInfoService;

    /**
     * 查询附近机器设备
     *
     * @param location
     * @return
     */
    @RequestMapping("/location/searchNearBy")
    public Object searchNearBy(@RequestParam(defaultValue = "28.070478,113.061809") String location) {
        return ResponseUtil.ok(lbsTableService.searchNearBy(location));
    }

    /**
     * 根据条件查询
     *
     * @param
     * @param page  页码
     * @param limit 每页显示的记录数
     * @param sort  排序字段
     * @param order 排序规则,asc/desc
     * @return
     */
    @GetMapping("/dev/list")
    public Object selectByExample(@RequestParam(value = "devId", required = false) String devId,
                                  @RequestParam(value = "scenes", required = false) String scenes,
                                  @RequestParam(value = "employee", required = false) String employee,
                                  @RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer limit,
                                  @Sort @RequestParam(defaultValue = "add_time") String sort,
                                  @Order @RequestParam(defaultValue = "desc") String order) {
        return ResponseUtil.ok(devInfoService.selectByExample(devId, scenes, employee, page, limit, sort, order));
    }
}
